<?php
  /**
  * Contains menu entry captions as values and .inc.php-filenames as keys.
  * the keys are moreover used to identify the current page to display.
  */
  $mainnav = Array('start' => 'welcome!',
                   'about' => 'what we do',
                   'board' => 'dashboard',
                   'galleries' => 'galleries',
                   'people' => 'people',
                   'gear' => 'gear hire',
                   'links' => 'links',
                   'contact' => 'contact us'
				   );
                   
  /**
  * contains the subtopics in the same way as above.
  * non-existent entry in this array means there are no subtopics
  * 
  * these values are also used in v_global.inc.php to connect the types to the database.
  * these values MUST match to make it work! @see v_global.inc.php. (for the dashboard)
  */
  $subnavs = Array('about' => Array('trips' => 'trips',
                                    'social' => 'social',
                                    'polo' => 'polo',
                                    'conservation' => 'conservation',
                                    'training' => 'training'),
                   'board' => Array('general' => 'general',
                                    'events' => 'events',
                                    'lost' => 'lost & found',
                                    'buy' => 'buy & sell',
                                    'polo' => 'polo')
                  );
                  
  /**
  * More functionality if one is logged in.
  */
  if ($_SESSION['logged']) 
  {
    $mainnav['member'] = $_SESSION['rights'] & $r_webmaster ? 'members':'my details';
    $mainnav['minutes'] = 'minutes';
    if ($_SESSION['rights'] & ($r_webmaster | $r_comittee)) 
    {
        $mainnav['news'] = 'newsletter';
        
    }
    if ($_SESSION['rights'] & $r_webmaster) 
    {
        $mainnav['log'] = 'log';
        $mainnav['trips'] = 'trips (beta)';
        $subnavs['member'] = Array('profile'=>'my details','members'=>'member list','member'=>'member details');
    }
  }
  
  /**
  *  Contains all topics that have a specific background.
  *  The images are stored in the pics folder with according names like "header_<topic>.jpg"
  */
  $headerimages = Array('trips','social','polo','galleries','gear','conservation');
  
  /**
  * @return the main navigation of left side
  */
  function nav_getMainNav() {
      global $mainnav;
      $res = '<table>';
      foreach($mainnav as $file => $caption) {
          $res .= '<tr><td>';
          $res .= ($_SESSION['topic'] == $file) ? '<font class="nav_sel">'.$caption.'</font>'
                                                  : '<a href="'.$_SERVER['PHP_SELF'].'?topic='.$file.'" class="nav">'.$caption.'</a>'; 
          $res .= '</td></tr>';
      }         
      $res .= '</table>';                      
      return $res;
  }
  
  /**
  * @return subnavigation according to currently selected main content
  */
  function nav_getSubNav() {
      global $mainnav,$subnavs;
      #$res = $mainnav[$_SESSION['topic']];
      if (is_array($subnavs[$_SESSION['topic']])) {
          $rarr = Array();
          #$res = '<table style="position:relative; left:-1px; top:-1px"><tr>';
          foreach($subnavs[$_SESSION['topic']] as $file => $caption) {
            #$res .= '<td>';
            
            $hlp = ($_SESSION['subtopic'] == $file) 
                    ? '<font class="subnav_sel">'.$caption.'</font>'
                    : '<a href="'.$_SERVER['PHP_SELF'].'?subtopic='.$file.'" class="subnav">'.$caption.'</a>';
            array_push($rarr,$hlp);
            #$res .= '</td>';
          }
          $res = implode(' - ',$rarr);
          #$res .= '</tr></table>';
      }
      return $res;
  }
  
  /**
  * @return the according background image to the selected content
  */
  function nav_getHeaderBackground() {
      global $mainnav,$subnavs,$headerimages;
      # Default image
      $result = 'general';
      $topic = $_SESSION['subtopic'] ? $_SESSION['subtopic']:$_SESSION['topic'];
      if (in_array($topic,$headerimages)) {
          $result = $topic;
      }
      return 'header_'.$result.'.jpg';
  }
  
  /**
  * @return the caption of the current topic
  */
  function nav_getCaption() {
      global $mainnav,$subnavs;
      return $_SESSION['subtopic'] ? $subnavs[$_SESSION['topic']][$_SESSION['subtopic']]:$mainnav[$_SESSION['topic']];
  }
?>